#!coding=utf-8
from django.db import models


class WMenu(models.Model):
    """
    微信菜单
    """
    MENU_TYPE_CHOICES = (('click', u'点击'), ('view', u'查看',), ('parent', u'父菜单'))
    parent = models.ForeignKey('self', verbose_name=u'父菜单', null=True, blank=True, \
                               related_name='children')
    menu_type = models.CharField(u'菜单类型', max_length=10, choices=MENU_TYPE_CHOICES, \
                                 help_text=u'类型为"父菜单",则必须要有子菜单')
    name = models.CharField(u'菜单名称', max_length=20)
    value = models.CharField(u'值', help_text=u'类型为"点击",则输入键码，如果类型为"查看",则输入url', \
                             max_length=256, null=True, blank=True)
    position = models.IntegerField(u'顺序')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = u"微信菜单"
        verbose_name_plural = u"微信菜单管理"


class User(models.Model):
    """
    用户
    """
    SEX_CHOICES = (('1', u'男'), ('0', u'女'), ('2', u'未提交'))
    openid = models.CharField(max_length=50, blank=False, primary_key=True)
    nickname = models.CharField(u'昵称', max_length=50, blank=True, null=True)
    sex = models.CharField(u'性别', choices=SEX_CHOICES, default='2', max_length=10, blank=True, null=True)
    telephone = models.CharField(u'手机号', max_length=11, blank=True, null=True)
    is_active = models.BooleanField(u'是否验证', default=False)
    active_at = models.CharField(u'最新手机验证时间', max_length=50, blank=True, null=True)
    latitude = models.CharField(u'经度', max_length=50, blank=True, null=True)
    longitude = models.CharField(u'纬度', max_length=50, blank=True, null=True)
    precision = models.CharField(u'精度', max_length=50, blank=True, null=True)
    modify_at = models.CharField(u'最新经纬度时间', max_length=50, blank=True, null=True)
    city = models.CharField(u'城市', max_length=100, blank=True, null=True)
    province = models.CharField(u'省份', max_length=100, blank=True, null=True)
    headimgurl = models.URLField(u'用户头像图片地址', blank=True, null=True)
    subscribe_time = models.CharField(u'关注公众账号时间', max_length=50, blank=True, null=True)

    def __unicode__(self):
        return '<%s %s[%s]>' % ("tmweixin.User", self.openid, self.nickname)

    class Meta:
        verbose_name = u"用户"
        verbose_name_plural = u"用户管理"


